package org.example.service;

import java.util.List;
import org.example.dao.GroupModelDao;
import org.example.entity.GroupModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
public class GroupServiceImlp
{
  @Autowired GroupModelDao dao;

  public GroupServiceImlp()
  {
    super();
    // TODO Auto-generated constructor stub
  }
  

  @Transactional(propagation = Propagation.MANDATORY)
  public GroupModel GroupModelPersist(GroupModel model) {
    if (model.getId() == 0)
    {
      model = dao.create(model);
    }
    else
    {
      model = dao.update(model);
    }
    return model;
  }
  
  @Transactional(propagation = Propagation.MANDATORY)
  public boolean ruleRemove(GroupModel model)
  {
    boolean r = dao.delete(model);
    return r;
  }
  
  @Transactional(propagation = Propagation.MANDATORY, readOnly = true)
  public List<GroupModel> GroupModelList()
  {
    return dao.findAll();
  }
  
  @Transactional(propagation = Propagation.MANDATORY, readOnly = true)
  public GroupModel GroupModelFind(int id)
  {
    return dao.find(id);
  }
}
